﻿const sqlite3 = require('sqlite3').verbose()
const config = require('../config/config')


let query = ( sql, values) => {
  return new Promise(function(resolve, reject) {
        let db =  new sqlite3.Database(config.sqlite.database.name,
            function(err) {
                if(err) {
                    reject("Open error: "+ err.message)
                    return;
                }
            }
        )  

        db.all(sql, values, function(err, row)  {
            console.log(row);
            if(err){

                reject("Read error: " + err.message)
            }
            else {
                db.close(); 
                resolve(row)
            }
        })
                
    })
}
module.exports = query;